#include<iostream>
using namespace std;
#include<string>
class Solution {
public:
    string compressedString(string word) {
        string ans;
        int sum = 1, n = word.size();
        char pre = 0;
        for (int i = 0; i < n; ++i) {
            if (pre == 0) {
                sum = 1;
                pre = word[i];
            }
            else {
                if (word[i] == pre&&sum<9)
                    ++sum;
                else {
                    ans.push_back(sum+'0');
                    ans.push_back(pre);
                    sum = 1;
                    pre = word[i];
                }
            }
        }
        if (sum) {
            ans.push_back(sum + '0');
            ans.push_back(pre);
        }
        return ans;
    }
};